﻿Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Text.RegularExpressions

Partial Class nFileKT
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Dim arrayCode(13, 17) As String

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        If Not Page.IsPostBack Then

        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Not Page.IsValid Then Exit Sub
        On Error GoTo hErr
        'Open a file for reading
        Dim strName, strCode As String
        Dim iIndex, iCount As Int16
        iCount = 0
        strName = txtName.Text
        Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        'Dim contents As String = objStreamReader.ReadToEnd()
        Dim sString
        Dim strDataFields() As String
        Dim i, intMin, iUpdate, iInsert As Integer
        i = 0 : iUpdate = 0 : iInsert = 0
        Dim sSql As String
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim MyCommand As SqlCommand
        myConn.Open()
        MyCommand = New SqlCommand("select 1 from kichthuoc", myConn)
        While objStreamReader.Peek() <> -1
            sString = objStreamReader.ReadLine()
            sString = remove_SpeKey(sString)
            If Trim(sString) <> "" Then
                If i > 0 Then
                    ' Data 
                    'On Error Resume Next
                    strDataFields = Split(sString, ",")
                    If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                        sSql = "select count(1) from kichthuoc where makt='" + strDataFields(0).ToString + "' "
                        MyCommand = New SqlCommand(sSql, myConn)
                        If MyCommand.ExecuteScalar > 0 Then
                            sSql = "update kichthuoc set tensp=@tensp,ban=@ban,s1=@s1,s2=@s2,s3=@s3,s4=@s4,s5=@s5,s6=@s6 where makt=@makt"
                            iUpdate += 1
                        Else
                            sSql = "insert into kichthuoc(makt,tensp,ban, s1,s2,s3,s4,s5,s6) values(@makt,@tensp,@ban,@s1,@s2,@s3,@s4,@s5,@s6)"
                            iInsert += 1
                        End If
                        On Error GoTo SQLError
                        MyCommand.CommandText = sSql
                        MyCommand.Parameters.Add(New SqlParameter("@makt", strDataFields(0)))
                        MyCommand.Parameters.Add(New SqlParameter("@tensp", strDataFields(1)))
                        MyCommand.Parameters.Add(New SqlParameter("@ban", strDataFields(2)))
                        MyCommand.Parameters.Add(New SqlParameter("@s1", strDataFields(3)))
                        MyCommand.Parameters.Add(New SqlParameter("@s2", strDataFields(4)))
                        MyCommand.Parameters.Add(New SqlParameter("@s3", strDataFields(5)))
                        MyCommand.Parameters.Add(New SqlParameter("@s4", IIf(strDataFields(6) = "", DBNull.Value, strDataFields(6))))
                        MyCommand.Parameters.Add(New SqlParameter("@s5", IIf(strDataFields(7) = "", DBNull.Value, strDataFields(7))))
                        MyCommand.Parameters.Add(New SqlParameter("@s6", IIf(strDataFields(8) = "", DBNull.Value, strDataFields(8))))
                        MyCommand.ExecuteNonQuery()
                        MyCommand.Dispose()
                        iCount += 1
SQLError:
                    End If
                End If
                i = i + 1
            End If
        End While
        objStreamReader.Close()
        Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
        MyCommand.Dispose()
        myConn.Close()
        Exit Sub
hErr:
        objStreamReader.Close()
        MyCommand.Dispose()
        myConn.Close()
    End Sub

    Private Function remove_SpeKey(ByVal vString As String) As String
        Dim strString As String
        strString = Replace(vString, """", "")
        Return strString
    End Function

    '    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    '        If Not Page.IsValid Then Exit Sub
    '        On Error GoTo hErr
    '        'Open a file for reading
    '        Dim strName, strCode As String
    '        Dim iIndex, iCount As Int16
    '        iCount = 0
    '        strName = txtName.Text
    '        Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
    '        'Get a StreamReader class that can be used to read the file
    '        Dim objStreamReader As StreamReader
    '        objStreamReader = File.OpenText(FILENAME)

    '        'Now, read the entire file into a string
    '        'Dim contents As String = objStreamReader.ReadToEnd()
    '        Dim sString
    '        Dim strDataFields() As String
    '        Dim i, intMin, iUpdate, iInsert As Integer
    '        i = 0 : iUpdate = 0 : iInsert = 0
    '        Dim sSql As String
    '        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
    '        Dim MyCommand As SqlCommand
    '        myConn.Open()
    '        MyCommand = New SqlCommand("select 1 from khachsan", myConn)
    '        While objStreamReader.Peek() <> -1
    '            sString = objStreamReader.ReadLine()
    '            sString = remove_SpeKey(sString)
    '            If Trim(sString) <> "" Then
    '                If i > 0 Then
    '                    ' Data 
    '                    'On Error Resume Next
    '                    strDataFields = Split(sString, ";")
    '                    If strDataFields(0) <> "" And strDataFields(1) <> "" Then
    '                        MyCommand = New SqlCommand(sSql, myConn)
    '                        sSql = "insert into khachsan(tenks,tenkse,diachi,diachie,diachig,diachis,quan_huyen,quan_huyene,tinh_tp,tinh_tpe,dienthoai,hangsao,resort,tinh_tp1,tinh_tp1e) values(@tenks,@tenkse,@diachi,@diachie,@diachig,@diachis,@quan_huyen,@quan_huyene,@tinh_tp,@tinh_tpe,@dienthoai,@hangsao,@resort,@tinh_tp1,@tinh_tp1e)"
    '                        iInsert += 1

    '                        On Error GoTo SQLError
    '                        MyCommand.CommandText = sSql
    '                        MyCommand.Parameters.Add(New SqlParameter("@tenks", strDataFields(0)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@tenkse", strDataFields(1)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@diachi", strDataFields(2)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@diachie", strDataFields(3)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@diachig", strDataFields(4)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@diachis", strDataFields(5)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@quan_huyen", strDataFields(6)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@quan_huyene", strDataFields(7)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@tinh_tp", strDataFields(8)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@tinh_tpe", strDataFields(9)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@dienthoai", strDataFields(10)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@hangsao", IIf(strDataFields(11) = "", DBNull.Value, strDataFields(11))))

    '                        MyCommand.Parameters.Add(New SqlParameter("@resort", strDataFields(12)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@tinh_tp1", strDataFields(13)))
    '                        MyCommand.Parameters.Add(New SqlParameter("@tinh_tp1e", strDataFields(14)))
    '                        MyCommand.ExecuteNonQuery()
    '                        MyCommand.Dispose()
    '                        iCount += 1
    'SQLError:
    '                    End If
    '                End If
    '                i = i + 1
    '            End If
    '        End While
    '        objStreamReader.Close()
    '        Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
    '        MyCommand.Dispose()
    '        myConn.Close()
    '        Exit Sub
    'hErr:
    '        objStreamReader.Close()
    '        MyCommand.Dispose()
    '        myConn.Close()
    '    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Not Page.IsValid Then Exit Sub
        On Error GoTo hErr
        'Open a file for reading
        Dim strName, strCode As String
        Dim iIndex, iCount As Int16
        iCount = 0
        strName = txtName.Text
        Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        'Dim contents As String = objStreamReader.ReadToEnd()
        Dim sString As String
        Dim strDataFields() As String
        Dim i, intMin, iUpdate, iInsert As Integer
        i = 0 : iUpdate = 0 : iInsert = 0
        Dim sSql As String = Nothing
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim MyCommand As SqlCommand
        myConn.Open()
        MyCommand = New SqlCommand("select 1 from khachsan", myConn)
        While objStreamReader.Peek() <> -1
            sString = objStreamReader.ReadLine()
            sString = remove_SpeKey(sString)
            If Trim(sString) <> "" Then
                If i > 0 Then
                    ' Data 
                    'On Error Resume Next
                    strDataFields = Split(sString, ";")
                    If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                        MyCommand = New SqlCommand(sSql, myConn)
                        sSql = "insert into khachsan(tenks,diachi,quan_huyen,tinh_tp, dienthoai,hangsao,resort,tinh_tp1,web,chuatrangbi) values(@tenks,@diachi,@quan_huyen,@tinh_tp, @dienthoai,@hangsao,@resort,@tinh_tp1,@web,@chuatrangbi)"
                        iInsert += 1

                        On Error GoTo SQLError
                        MyCommand.CommandText = sSql
                        MyCommand.Parameters.Add(New SqlParameter("@tenks", strDataFields(0)))
                        MyCommand.Parameters.Add(New SqlParameter("@diachi", strDataFields(1)))
                        MyCommand.Parameters.Add(New SqlParameter("@quan_huyen", strDataFields(2)))
                        MyCommand.Parameters.Add(New SqlParameter("@tinh_tp", strDataFields(3)))
                        MyCommand.Parameters.Add(New SqlParameter("@dienthoai", strDataFields(4)))
                        MyCommand.Parameters.Add(New SqlParameter("@hangsao", IIf(strDataFields(5) = "", DBNull.Value, strDataFields(5))))

                        MyCommand.Parameters.Add(New SqlParameter("@resort", strDataFields(6)))
                        MyCommand.Parameters.Add(New SqlParameter("@tinh_tp1", strDataFields(7)))
                        MyCommand.Parameters.Add(New SqlParameter("@web", strDataFields(8)))
                        MyCommand.Parameters.Add(New SqlParameter("@chuatrangbi", IIf(strDataFields(9) = "", DBNull.Value, strDataFields(9))))

                        MyCommand.ExecuteNonQuery()
                        MyCommand.Dispose()
                        iCount += 1
SQLError:
                    End If
                End If
                i = i + 1
            End If
        End While
        objStreamReader.Close()
        Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
        MyCommand.Dispose()
        myConn.Close()
        Exit Sub
hErr:
        objStreamReader.Close()
        MyCommand.Dispose()
        myConn.Close()
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Not Page.IsValid Then Exit Sub
        On Error GoTo hErr
        'Open a file for reading
        Dim strName, strCode As String
        Dim iIndex, iCount As Int16
        iCount = 0
        strName = txtName.Text
        Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        'Dim contents As String = objStreamReader.ReadToEnd()
        Dim sString
        Dim strDataFields() As String
        Dim i, intMin, iUpdate, iInsert As Integer
        i = 0 : iUpdate = 0 : iInsert = 0
        Dim sSql As String
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim MyCommand As SqlCommand
        myConn.Open()
        MyCommand = New SqlCommand("select 1 from daily", myConn)
        While objStreamReader.Peek() <> -1
            sString = objStreamReader.ReadLine()
            sString = remove_SpeKey(sString)
            If Trim(sString) <> "" Then
                If i > 0 Then
                    ' Data 
                    'On Error Resume Next
                    strDataFields = Split(sString, ",")
                    If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                        MyCommand = New SqlCommand(sSql, myConn)
                        sSql = "update daily set bando=@bando where iddaily=@iddaily"
                        iUpdate += 1
                        On Error GoTo SQLError
                        MyCommand.CommandText = sSql
                        MyCommand.Parameters.Add(New SqlParameter("@iddaily", strDataFields(0)))
                        MyCommand.Parameters.Add(New SqlParameter("@bando", strDataFields(1)))
                        MyCommand.ExecuteNonQuery()
                        MyCommand.Dispose()
                        iCount += 1
SQLError:
                    End If
                End If
                i = i + 1
            End If
        End While
        objStreamReader.Close()
        Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
        MyCommand.Dispose()
        myConn.Close()
        Exit Sub
hErr:
        objStreamReader.Close()
        MyCommand.Dispose()
        myConn.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Not Page.IsValid Then Exit Sub
        On Error GoTo hErr
        'Open a file for reading
        Dim strName, strCode As String
        Dim iIndex, iCount As Int16
        iCount = 0
        strName = txtName.Text
        Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        'Dim contents As String = objStreamReader.ReadToEnd()
        Dim sString
        Dim strDataFields() As String
        Dim i, intMin, iUpdate, iInsert As Integer
        i = 0 : iUpdate = 0 : iInsert = 0
        Dim sSql As String
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim MyCommand As SqlCommand
        myConn.Open()
        MyCommand = New SqlCommand("select 1 from daily", myConn)
        While objStreamReader.Peek() <> -1
            sString = objStreamReader.ReadLine()
            sString = remove_SpeKey(sString)
            If Trim(sString) <> "" Then
                If i > 0 Then
                    ' Data 
                    'On Error Resume Next
                    strDataFields = Split(sString, ";")
                    If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                        MyCommand = New SqlCommand(sSql, myConn)
                        sSql = "update daily set diachis=@diachis, khuvucs=@khuvucs where iddaily=@iddaily"
                        iUpdate += 1
                        On Error GoTo SQLError
                        MyCommand.CommandText = sSql
                        MyCommand.Parameters.Add(New SqlParameter("@iddaily", strDataFields(0)))
                        MyCommand.Parameters.Add(New SqlParameter("@diachis", strDataFields(1)))
                        MyCommand.Parameters.Add(New SqlParameter("@khuvucs", strDataFields(2)))
                        MyCommand.ExecuteNonQuery()
                        MyCommand.Dispose()
                        iCount += 1
SQLError:
                    End If
                End If
                i = i + 1
            End If
        End While
        objStreamReader.Close()
        Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
        MyCommand.Dispose()
        myConn.Close()
        Exit Sub
hErr:
        objStreamReader.Close()
        MyCommand.Dispose()
        myConn.Close()
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        If Not Page.IsValid Then Exit Sub
        Try
            'Open a file for reading
            Dim strName, strCode As String
            Dim iIndex, iCount As Int16
            iCount = 0
            strName = txtName.Text
            Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
            'Get a StreamReader class that can be used to read the file
            Dim objStreamReader As StreamReader
            objStreamReader = File.OpenText(FILENAME)

            'Now, read the entire file into a string
            'Dim contents As String = objStreamReader.ReadToEnd()
            Dim sString
            Dim strDataFields() As String
            Dim i, intMin, iUpdate, iInsert As Integer
            i = 0 : iUpdate = 0 : iInsert = 0
            Dim sSql As String
            Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
            Dim MyCommand As SqlCommand
            Dim temp As String
            myConn.Open()
            MyCommand = New SqlCommand("select 1 from daily", myConn)
            While objStreamReader.Peek() <> -1
                sString = objStreamReader.ReadLine()
                sString = remove_SpeKey(sString)
                If Trim(sString) <> "" Then
                    If i > 0 Then
                        ' Data 
                        strDataFields = Split(sString, Chr(9))
                        If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                            MyCommand = New SqlCommand(sSql, myConn)
                            sSql = "update daily set diachiv=@diachiv where dienthoai=@dienthoai"
                            iUpdate += 1

                            MyCommand.CommandText = sSql
                            MyCommand.Parameters.Add(New SqlParameter("@dienthoai", strDataFields(0)))
                            MyCommand.Parameters.Add(New SqlParameter("@diachiv", strDataFields(1)))
                            MyCommand.ExecuteNonQuery()
                            MyCommand.Dispose()
                            iCount += 1

                        End If
                    End If
                    i = i + 1
                End If
            End While
            objStreamReader.Close()
            Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
            MyCommand.Dispose()
            myConn.Close()
            Label3.Text = "Update Successfully"
        Catch ex As Exception
            Label3.Text = "hErr:" & ex.Message
        End Try
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If Not Page.IsValid Then Exit Sub
        Try
            'Open a file for reading
            Dim strName, strCode As String
            Dim iIndex, iCount As Int16
            iCount = 0
            strName = txtName.Text
            Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
            'Get a StreamReader class that can be used to read the file
            Dim objStreamReader As StreamReader
            objStreamReader = File.OpenText(FILENAME)

            'Now, read the entire file into a string
            'Dim contents As String = objStreamReader.ReadToEnd()
            Dim sString
            Dim strDataFields() As String
            Dim i, intMin, iUpdate, iInsert As Integer
            i = 0 : iUpdate = 0 : iInsert = 0
            Dim sSql As String
            Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
            Dim MyCommand As SqlCommand
            Dim temp As String
            myConn.Open()
            MyCommand = New SqlCommand("select 1 from daily", myConn)
            While objStreamReader.Peek() <> -1
                sString = objStreamReader.ReadLine()
                sString = remove_SpeKey(sString)
                If Trim(sString) <> "" Then
                    If i > 0 Then
                        ' Data 
                        strDataFields = Split(sString, Chr(9))
                        If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                            MyCommand = New SqlCommand(sSql, myConn)
                            sSql = "update daily set tendailyV = @tendailyV, tendailyEGC = @tendailyEGC where dienthoai=@dienthoai"
                            iUpdate += 1

                            MyCommand.CommandText = sSql
                            MyCommand.Parameters.Add(New SqlParameter("@dienthoai", strDataFields(0)))
                            MyCommand.Parameters.Add(New SqlParameter("@tendailyV", strDataFields(1)))
                            MyCommand.Parameters.Add(New SqlParameter("@tendailyEGC", chuyenThanhKhongDau(strDataFields(1))))
                            MyCommand.ExecuteNonQuery()
                            MyCommand.Dispose()
                            iCount += 1

                        End If
                    End If
                    i = i + 1
                End If
            End While
            objStreamReader.Close()
            Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
            MyCommand.Dispose()
            myConn.Close()
            Label3.Text = "Update Successfully"
        Catch ex As Exception
            Label3.Text = "hErr:" & ex.Message
        End Try

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        If Not Page.IsValid Then Exit Sub
        Try
            'Open a file for reading
            Dim strName, strCode As String
            Dim iIndex, iCount As Int16
            iCount = 0
            strName = txtName.Text
            Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
            'Get a StreamReader class that can be used to read the file
            Dim objStreamReader As StreamReader
            objStreamReader = File.OpenText(FILENAME)

            'Now, read the entire file into a string
            'Dim contents As String = objStreamReader.ReadToEnd()
            Dim sString
            Dim strDataFields() As String
            Dim i, intMin, iUpdate, iInsert As Integer
            i = 0 : iUpdate = 0 : iInsert = 0
            Dim sSql As String
            Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
            Dim MyCommand As SqlCommand
            Dim temp As String
            myConn.Open()
            MyCommand = New SqlCommand("select 1 from daily", myConn)
            While objStreamReader.Peek() <> -1
                sString = objStreamReader.ReadLine()
                sString = remove_SpeKey(sString)
                If Trim(sString) <> "" Then
                    If i > 0 Then
                        ' Data 
                        strDataFields = Split(sString, Chr(9))
                        If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                            MyCommand = New SqlCommand(sSql, myConn)
                            sSql = "update daily set hinhanh = @tenhinh where iddaily=@iddaily"
                            iUpdate += 1

                            MyCommand.CommandText = sSql
                            MyCommand.Parameters.Add(New SqlParameter("@iddaily", strDataFields(0)))
                            MyCommand.Parameters.Add(New SqlParameter("@tenhinh", Trim(strDataFields(1))))
                            MyCommand.ExecuteNonQuery()
                            MyCommand.Dispose()
                            iCount += 1

                        End If
                    End If
                    i = i + 1
                End If
            End While
            objStreamReader.Close()
            Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
            MyCommand.Dispose()
            myConn.Close()
            Label3.Text = "Update Successfully"
        Catch ex As Exception
            Label3.Text = "hErr:" & ex.Message
        End Try

    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        If Not Page.IsValid Then Exit Sub

        Try
            'Open a file for reading
            Dim strName As String
            Dim iCount As Int16
            iCount = 0
            strName = txtName.Text
            Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
            'Get a StreamReader class that can be used to read the file
            Dim objStreamReader As StreamReader
            objStreamReader = File.OpenText(FILENAME)

            'Now, read the entire file into a string
            'Dim contents As String = objStreamReader.ReadToEnd()
            Dim sString As String
            Dim strDataFields() As String
            Dim i, iUpdate, iInsert As Integer
            i = 0 : iUpdate = 0 : iInsert = 0
            Dim sSql As String = Nothing
            Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
            Dim MyCommand As SqlCommand
            myConn.Open()
            MyCommand = New SqlCommand("select 1 from daily", myConn)
            While objStreamReader.Peek() <> -1
                sString = objStreamReader.ReadLine()
                sString = remove_SpeKey(sString)
                If Trim(sString) <> "" Then
                    If i > 0 Then
                        ' Data 
                        strDataFields = Split(sString, Chr(9))
                        If strDataFields(0) <> "" And strDataFields(1) <> "" Then
                            MyCommand = New SqlCommand(sSql, myConn)
                            sSql = "update daily set bando = @tenhinh where dienthoai like '%" & Trim(strDataFields(0)) & "%'"
                            iUpdate += 1

                            MyCommand.CommandText = sSql
                            MyCommand.Parameters.Add(New SqlParameter("@tenhinh", Trim(strDataFields(1))))
                            MyCommand.ExecuteNonQuery()
                            MyCommand.Dispose()
                            iCount += 1

                        End If
                    End If
                    i = i + 1
                End If
            End While
            objStreamReader.Close()
            Label1.Text = iCount.ToString + "::" + " Update: " + iUpdate.ToString + " Insert: " + iInsert.ToString
            MyCommand.Dispose()
            myConn.Close()
            Label3.Text = "Update Successfully"
        Catch ex As Exception
            Label3.Text = "hErr:" & ex.Message
        End Try

    End Sub


    Private Function chuyenThanhKhongDau(ByVal source As String) As String
        arrayCodeInilt()
        Dim result, temp As String
        Dim i, j, n As Byte
        ' Gán cho biến result nội dung trong TxtViết
        result = source
        ' Tiến hành thay thế , lọc bỏ dấu cho chuỗi
        For j = 0 To 13
            For i = 1 To 17
                temp = result.Replace(arrayCode(j, i), arrayCode(j, 0))
                result = temp
            Next
        Next
        Return result
    End Function

    Private Sub arrayCodeInilt()
        Dim i, j, n As Byte
        Dim Chuoi As String
        Dim Thga, Thge, Thgo, Thgu, Thgi, Thgd, Thgy As String
        Dim HoaA, HoaE, HoaO, HoaU, HoaI, HoaD, HoaY As String
        Chuoi = "aAeEoOuUiIdDyY"
        Thga = "áàạảãâấầậẩẫăắằặẳẵ"
        HoaA = "ÁÀẠẢÃÂẤẦẬẨẪĂẮẰẶẲẴ"
        Thge = "éèẹẻẽêếềệểễeeeeee"
        HoaE = "ÉÈẸẺẼÊẾỀỆỂỄEEEEEE"
        Thgo = "óòọỏõôốồộổỗơớờợởỡ"
        HoaO = "ÓÒỌỎÕÔỐỒỘỔỖƠỚỜỢỞỠ"
        Thgu = "úùụủũưứừựửữuuuuuu"
        HoaU = "ÚÙỤỦŨƯỨỪỰỬỮUUUUUU"
        Thgi = "íìịỉĩiiiiiiiiiiii"
        HoaI = "ÍÌỊỈĨIIIIIIIIIIII"
        Thgd = "đdddddddddddddddd"
        HoaD = "ĐDDDDDDDDDDDDDDDD"
        Thgy = "ýỳỵỷỹyyyyyyyyyyyy"
        HoaY = "ÝỲỴỶỸYYYYYYYYYYYY"
        'Nạp vào trong arrayCode các ký tự
        'Nạp vào từng đầu hàng các ký tự không dấu
        'Nạp vào cột đầu tiên
        For i = 0 To 13
            arrayCode(i, 0) = Mid(Chuoi, i + 1, 1)
        Next
        'Nạp vào từng ô các ký tự có dấu
        For j = 1 To 17
            For i = 1 To 17
                arrayCode(0, i) = Mid(Thga, i, 1) 'Nạp từng ký tự trong chuỗi Thga vào từng ô trong hàng 0
                arrayCode(1, i) = Mid(HoaA, i, 1) 'Nạp từng ký tự trong chuỗi HoaA vào từng ô trong  hàng 1
                arrayCode(2, i) = Mid(Thge, i, 1) 'Nạp từng ký tự trong chuỗi Thge vào từng ô trong  hàng 2
                arrayCode(3, i) = Mid(HoaE, i, 1) 'Nạp từng ký tự trong chuỗi HoaE vào từng ô trong  hàng 3
                arrayCode(4, i) = Mid(Thgo, i, 1) 'Nạp từng ký tự trong chuỗi Thgo vào từng ô trong  hàng 4
                arrayCode(5, i) = Mid(HoaO, i, 1) 'Nạp từng ký tự trong chuỗi HoaO vào từng ô trong  hàng 5
                arrayCode(6, i) = Mid(Thgu, i, 1) 'Nạp từng ký tự trong chuỗi Thgu vào từng ô trong  hàng 6
                arrayCode(7, i) = Mid(HoaU, i, 1) 'Nạp từng ký tự trong chuỗi HoaU vào từng ô trong  hàng 7
                arrayCode(8, i) = Mid(Thgi, i, 1) 'Nạp từng ký tự trong chuỗi Thgi vào từng ô trong  hàng 8
                arrayCode(9, i) = Mid(HoaI, i, 1) 'Nạp từng ký tự trong chuỗi HoaI vào từng ô trong  hàng 9
                arrayCode(10, i) = Mid(Thgd, i, 1) 'Nạp từng ký tự trong chuỗi Thgd vào từng ô trong  hàng 10
                arrayCode(11, i) = Mid(HoaD, i, 1) 'Nạp từng ký tự trong chuỗi HoaD vào từng ô trong  hàng 11
                arrayCode(12, i) = Mid(Thgy, i, 1) 'Nạp từng ký tự trong chuỗi Thgy vào từng ô trong  hàng 12
                arrayCode(13, i) = Mid(HoaY, i, 1) 'Nạp từng ký tự trong chuỗi HoaY vào từng ô trong  hàng 13
            Next
        Next
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If Not Page.IsValid Then Exit Sub

        'Open a file for reading
        Dim strName, strCode As String
        Dim iIndex, iCount As Int16
        iCount = 0
        strName = txtName.Text
        Dim FILENAME As String = Server.MapPath("upload\" & strName.ToString)
        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        'Dim contents As String = objStreamReader.ReadToEnd()
        Dim sString
        Dim strDataFields() As String
        Dim i, intMin, iUpdate, iInsert As Integer
        i = 0 : iUpdate = 0 : iInsert = 0
        Dim sSql As String
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("cons"))
        Dim MyCommand As SqlCommand
        Dim temp As String
        myConn.Open()
        MyCommand = New SqlCommand("select 1 from daily", myConn)
        While objStreamReader.Peek() <> -1
            sString = objStreamReader.ReadLine()
            sString = remove_SpeKey(sString)
            If Trim(sString) <> "" Then
                If i > 0 Then
                    ' Data 
                    Try
                        MyCommand = New SqlCommand(sSql, myConn)
                        sSql = sString
                        MyCommand.CommandText = sString
                        MyCommand.ExecuteNonQuery()
                        MyCommand.Dispose()
                        iCount += 1
                    Catch ex As Exception
                        Label3.Text &= "<br />" & sString
                    End Try
                End If
                i = i + 1
            End If
        End While
        objStreamReader.Close()
        MyCommand.Dispose()
        myConn.Close()


    End Sub
End Class
